import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mobile_vpn/common/cpn/cpn_view_state.dart';
import 'package:mobile_vpn/pages/set_up/set_logic.dart';
import '../../common/cpn/sliver_app_bar.dart';
import '../../theme/color_palettes.dart';

class NotificationSettingsPage extends CpnViewState<SetLogic> {

  NotificationSettingsPage({Key? key}) : super(key: key, bindViewState: false);
  // 定义状态变量
  final RxBool _notificationEnabled = true.obs;
  final RxBool _connectionNotifications = true.obs;
  final RxBool _promotionalNotifications = true.obs;
  final RxBool _updateNotifications = true.obs;

  @override
  Widget buildBody(BuildContext context) {
    return CustomScrollView(
      slivers: [
        commonSliverAppBar(
          title: '通知设置',

        ),
        SliverToBoxAdapter(
          child: Padding(
            padding: EdgeInsets.all(20.w),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 通知总开关
                _buildNotificationSwitch(),
                SizedBox(height: 24.h),

                // 通知类型标题
                Text(
                  '通知类型',
                  style: TextStyle(
                    fontSize: 32.sp,
                    fontWeight: FontWeight.bold,
                    color: ColorPalettes.instance.firstText,
                  ),
                ),
                SizedBox(height: 16.h),

                // 连接通知
                _buildNotificationItem(
                  title: '连接通知',
                  subtitle: '当连接状态发生变化时通知',
                  value: _connectionNotifications.value,
                  onChanged: (value) {
                    _connectionNotifications.value = value;
                  },
                ),
                SizedBox(height: 12.h),

                // 促销通知
                _buildNotificationItem(
                  title: '促销通知',
                  subtitle: '接收最新的促销和优惠信息',
                  value: _promotionalNotifications.value,
                  onChanged: (value) {
                    _promotionalNotifications.value = value;
                  },
                ),
                SizedBox(height: 12.h),

                // 更新通知
                _buildNotificationItem(
                  title: '更新通知',
                  subtitle: '当有新版本可用时通知',
                  value: _updateNotifications.value,
                  onChanged: (value) {
                    _updateNotifications.value = value;
                  },
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  // 通知总开关
  Widget _buildNotificationSwitch() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          '通知',
          style: TextStyle(
            fontSize: 34.sp,
            fontWeight: FontWeight.w600,
            color: ColorPalettes.instance.firstText,
          ),
        ),

        Switch(
          value: _notificationEnabled.value,
          onChanged: (value) {
            _notificationEnabled.value = value;
            // 关闭总开关时，禁用所有通知类型
            if (!value) {
              _connectionNotifications.value = false;
              _promotionalNotifications.value = false;
              _updateNotifications.value = false;
            } else {
              _connectionNotifications.value = true;
              _promotionalNotifications.value = true;
              _updateNotifications.value = true;
            }
          },
          activeColor: ColorPalettes.instance.primary,
        ),
      ],
    );
  }

  // 通知类型选项
  Widget _buildNotificationItem({
    required String title,
    required String subtitle,
    required bool value,
    required Function(bool) onChanged,
  }) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 12.h, horizontal: 16.w),
      decoration: BoxDecoration(
        color: ColorPalettes.instance.background,
        borderRadius: BorderRadius.circular(8.r),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 4.r,
            offset: Offset(0, 2.w),
          ),
        ],
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(
                  fontSize: 30.sp,
                  fontWeight: FontWeight.w500,
                  color: ColorPalettes.instance.firstText,
                ),
              ),
              SizedBox(height: 4.h),
              Text(
                subtitle,
                style: TextStyle(
                  fontSize: 28.sp,
                  color: ColorPalettes.instance.secondText,
                ),
              ),
            ],
          ),



          Switch(
            value: value,
            onChanged: _notificationEnabled.value ? onChanged : null, // 总开关关闭时禁用
            activeColor: ColorPalettes.instance.primary,
         )
        ],
      ),
    );
  }
}


